﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace XEvents.Library
{
    internal struct dm_xe_session
    {
        internal string address;
        internal string name;
        internal int pending_buffers;
        internal int total_regular_buffers;
        internal Int64 regular_buffer_size;
        internal int total_large_buffers;
        internal Int64 large_buffer_size;
        internal Int64 total_buffer_size;
        internal int buffer_policy_flags;
        internal string buffer_policy_desc;
        internal int flags;
        internal string flag_desc;
        internal int dropped_event_count;
        internal int dropped_buffer_count;
        internal int blocked_event_fire_time;
        internal DateTime create_time;
        internal int largest_event_dropped_size;

        internal dm_xe_session(SqlDataReader dr)
        {
            address = (dr["address"] == DBNull.Value ? string.Empty : dr["address"]).ToString();
            name = (dr["name"] == DBNull.Value ? string.Empty : dr["name"]).ToString();
            Int32.TryParse((dr["pending_buffers"] == DBNull.Value ? "-1" : dr["pending_buffers"]).ToString(), out pending_buffers);
            Int32.TryParse((dr["total_regular_buffers"] == DBNull.Value ? "-1" : dr["total_regular_buffers"]).ToString(), out total_regular_buffers);
            Int64.TryParse((dr["regular_buffer_size"] == DBNull.Value ? "-1" : dr["regular_buffer_size"]).ToString(), out regular_buffer_size);
            Int32.TryParse((dr["total_large_buffers"] == DBNull.Value ? "-1" : dr["total_large_buffers"]).ToString(), out total_large_buffers);
            Int64.TryParse((dr["large_buffer_size"] == DBNull.Value ? "-1" : dr["large_buffer_size"]).ToString(), out large_buffer_size);
            Int64.TryParse((dr["total_buffer_size"] == DBNull.Value ? "-1" : dr["total_buffer_size"]).ToString(), out total_buffer_size);
            Int32.TryParse((dr["buffer_policy_flags"] == DBNull.Value ? "-1" : dr["buffer_policy_flags"]).ToString(), out buffer_policy_flags);
            buffer_policy_desc = (dr["buffer_policy_desc"] == DBNull.Value ? string.Empty : dr["buffer_policy_desc"]).ToString();
            Int32.TryParse((dr["flags"] == DBNull.Value ? "-1" : dr["flags"]).ToString(), out flags);
            flag_desc = (dr["flag_desc"] == DBNull.Value ? string.Empty : dr["flag_desc"]).ToString();
            Int32.TryParse((dr["dropped_event_count"] == DBNull.Value ? "-1" : dr["dropped_event_count"]).ToString(), out dropped_event_count);
            Int32.TryParse((dr["dropped_buffer_count"] == DBNull.Value ? "-1" : dr["dropped_buffer_count"]).ToString(), out dropped_buffer_count);
            Int32.TryParse((dr["blocked_event_fire_time"] == DBNull.Value ? "-1" : dr["blocked_event_fire_time"]).ToString(), out blocked_event_fire_time);
            DateTime.TryParse((dr["create_time"] == DBNull.Value ? "-1" : dr["create_time"]).ToString(), out create_time);
            Int32.TryParse((dr["largest_event_dropped_size"] == DBNull.Value ? "-1" : dr["largest_event_dropped_size"]).ToString(), out largest_event_dropped_size);
        }
    }
}
